    <script src="/jison/assets/js/jquery.js"></script> 
    <script src="/jison/assets/js/calculator.js"></script>
    <script>
      $(document).ready(function () {
        $("button").click(function () {
          try {
            var result = calculator.parse($("input").val())
            $("span").html(result);
          } catch (e) {
            $("span").html(String(e));
          }
        });
      });
    </script>
    <h1>Calculator demo</h1>
    <p>This demo parses mathematical expressions and returns the answer, keeping the correct order of operations. </p>
    <p>Enter an expression to evaluate, such as PI*4^2 + 5:</p>
    <p>
      <input type="text" value="PI*4^2 + 5" /> <button>equals</button> <span></span>
    </p>

    <h2>The grammar</h2>
    This Jison grammar was used to create the parser/evaluator:
    
    <pre>
      
      /* description: Parses end evaluates mathematical expressions. */

      /* lexical grammar */
      %lex
      %%
      \s+                   {/* skip whitespace */}
      [0-9]+("."[0-9]+)?\b  {return 'NUMBER';}
      "*"                   {return '*';}
      "/"                   {return '/';}
      "-"                   {return '-';}
      "+"                   {return '+';}
      "^"                   {return '^';}
      "("                   {return '(';}
      ")"                   {return ')';}
      "PI"                  {return 'PI';}
      "E"                   {return 'E';}
      &lt;&lt;EOF>>               {return 'EOF';}

      /lex

      /* operator associations and precedence */

      %left '+' '-'
      %left '*' '/'
      %left '^'
      %left UMINUS

      %start expressions

      %% /* language grammar */

      expressions
          : e EOF
              {return $1;}
          ;

      e
          : e '+' e
              {$$ = $1 + $3;}
          | e '-' e
              {$$ = $1 - $3;}
          | e '*' e
              {$$ = $1 * $3;}
          | e '/' e
              {$$ = $1 / $3;}
          | e '^' e
              {$$ = Math.pow($1, $3);}
          | '-' e %prec UMINUS
              {$$ = -$2;}
          | '(' e ')'
              {$$ = $2;}
          | NUMBER
              {$$ = Number(yytext);}
          | E
              {$$ = Math.E;}
          | PI
              {$$ = Math.PI;}
          ;

  </pre>
